package gdt.entity;

import gdt.entity.AbstractSecureEntity;
import gdt.entity.embeddable.Address;
import gdt.entity.embeddable.Contact;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

import javax.persistence.*;

import org.hibernate.validator.Email;
import org.hibernate.validator.NotEmpty;
import org.hibernate.validator.Pattern;
import org.hibernate.validator.Valid;

import static javax.persistence.FetchType.LAZY;

/**
 * Entity that represents a client of a group.
 * It has a list of projects executed for the client.
 */

@Entity
public class Client extends AbstractSecureEntity implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	@NotEmpty
	private String name;
	
	@Valid
	@Embedded
	private Address address = new Address();
	
	@Pattern(regex="[0-9]{0,50}")
	private String phone;
	
	@Pattern(regex="[0-9]{0,50}")
	private String fax;
	
	@Email
	private String email;
	
	private String url;
	
	@Valid
	@Embedded
	@AttributeOverrides({@AttributeOverride(name="name", column = @Column(name="contact_name")),
						 @AttributeOverride(name="email", column = @Column(name="contact_email")),
						 @AttributeOverride(name="mobile", column = @Column(name="contact_mobile")),
						 @AttributeOverride(name="phone", column = @Column(name="contact_phone")),
						 @AttributeOverride(name="fax", column = @Column(name="contact_fax"))})
	private Contact contact = new Contact();
	
	@ManyToOne(fetch=LAZY)
	private Group group;
	
	@OneToMany(fetch=LAZY, mappedBy = "client")
	private List<Project> projects = new LinkedList<Project>();

	
	public Client() {
		super();
	}   
	
	// ********************** Accessor Methods ********************** //
	
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}   
	public Address getAddress() {
		return this.address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}   
	public String getPhone() {
		return this.phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}   
	public String getFax() {
		return this.fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}   
	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}
	public String getUrl() {
		return this.url;
	}

	public void setUrl(String url) {
		this.url = url;
	}   
	public Contact getContact() {
		return this.contact;
	}

	public void setContact(Contact contact) {
		this.contact = contact;
	}
	public void setGroup(Group group) {
		this.group = group;
	}
	public Group getGroup() {
		return group;
	}
	public void setProjects(List<Project> projects) {
		this.projects = projects;
	}
	public List<Project> getProjects() {
		return projects;
	}
   
}
